/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aqu.controlador.CuentasPorPagar;

import aqu.bean.generico.BeanGenerico;
import aqu.persistencia.Dao.CuentasPorPagar.CxpTipoRetencionManager;
import aqu.persistencia.entity.CxpTipoRetencion;
import aqu.persistencia.utilidad.MessagesController;
import com.icesoft.faces.component.ext.RowSelectorEvent;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;

/**
 *
 * @author Verito Ramirez
 *         Victor Jaramillo
 */
@ManagedBean(name = "tipoRetencionController")
@ViewScoped
public class TipoRetencionController extends BeanGenerico {

    private CxpTipoRetencion tipoRetencion;
    private List<CxpTipoRetencion> lista;
    private CxpTipoRetencionManager cxpTipoRetencionManager = new CxpTipoRetencionManager();
    private boolean panelvisible;

    public TipoRetencionController() {

        tipoRetencion = new CxpTipoRetencion();
        lista = cxpTipoRetencionManager.getList();
    }

    public CxpTipoRetencionManager getCxpTipoRetencionManager() {
        return cxpTipoRetencionManager;
    }

    public void setCxpTipoRetencionManager(CxpTipoRetencionManager cxpTipoRetencionManager) {
        this.cxpTipoRetencionManager = cxpTipoRetencionManager;
    }

    public List<CxpTipoRetencion> getLista() {
        lista = cxpTipoRetencionManager.getList();
        return lista;
    }

    public void setLista(List<CxpTipoRetencion> lista) {
        this.lista = lista;
    }

    public CxpTipoRetencion getTipoRetencion() {
        return tipoRetencion;
    }

    public void setTipoRetencion(CxpTipoRetencion tipoRetencion) {
        this.tipoRetencion = tipoRetencion;
    }
    
    public boolean isPanelvisible() {
        return panelvisible;
    }

    public void setPanelvisible(boolean panelvisible) {
        this.panelvisible = panelvisible;
    }

    public void llamarPanelvisible(ActionEvent event) {
        panelvisible = !panelvisible;
    }

    public void nuevo(ActionEvent actionEvent) {
        tipoRetencion = new CxpTipoRetencion();
    }

    public String eliminar() {
        try {
            CxpTipoRetencion tipoRetencionTemp = (CxpTipoRetencion) (tipoRetencion);
            if (cxpTipoRetencionManager.delete(tipoRetencionTemp) == false) {
                llamarPanelvisible(null);
            }
        } catch (Exception e) {
            MessagesController.addInfo("Mensaje de error :", e.getMessage());
            llamarPanelvisible(null);
        }
        return "index";
    }

    public void insertar(ActionEvent actionEvent) {
        try {
            tipoRetencion.setCxpCodigoTipRet(MessagesController.obtenerkeyautomaticosinceros("cxp_tiporetencion", "CXP_CODIGO_TIPRET"));
            if (cxpTipoRetencionManager.create(tipoRetencion) == false) {
                llamarPanelvisible(null);
            }
            tipoRetencion = new CxpTipoRetencion();
        } catch (Exception e) {
            MessagesController.addInfo("Mensaje de error :", e.getMessage());
            llamarPanelvisible(null);
        }
    }

    public void modificar(ActionEvent actionEvent) {
        try {
            if (cxpTipoRetencionManager.update(tipoRetencion) == false) {
                llamarPanelvisible(null);
            }
        } catch (Exception e) {
            MessagesController.addInfo("Mensaje de error :", e.getMessage());
            llamarPanelvisible(null);
        }
    }

    public void rowSelectionListener(RowSelectorEvent event) {
        tipoRetencion = lista.get(event.getRow());
    }   
    
}